package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.Teacher;
import cn.edu.wfit.modules.infomanagement.service.ITeacherService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 老师管理Controller
 * 
 * @author 韩强
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController extends BaseController
{
    @Autowired
    private ITeacherService teacherService;


    /**
     * 查询老师管理列表
     */
    @RequiresPermissions("system:teacher:list")
    @GetMapping("/list")
    public TableDataInfo list(Teacher teacher)
    {

        startPage();
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        return getDataTable(list);
    }

    /**
     * 导出老师管理列表
     */
    @RequiresPermissions("system:teacher:export")
    @Log(title = "老师管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Teacher teacher)
    {
        List<Teacher> list = teacherService.selectTeacherList(teacher);
        ExcelUtil<Teacher> util = new ExcelUtil<Teacher>(Teacher.class);
        util.exportExcel(response, list, "老师管理数据");
    }

    /**
     * 获取老师管理详细信息
     */
    @RequiresPermissions("system:teacher:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(teacherService.selectTeacherByUserId(userId));
    }

    /**
     * 新增老师管理
     */
    @RequiresPermissions("system:teacher:add")
    @Log(title = "老师管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Teacher teacher)
    {
        return toAjax(teacherService.insertTeacher(teacher));
    }

    /**
     * 修改老师管理
     */
    @RequiresPermissions("system:teacher:edit")
    @Log(title = "老师管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Teacher teacher)
    {
        return toAjax(teacherService.updateTeacher(teacher));
    }

    /**
     * 删除老师管理
     */
    @RequiresPermissions("system:teacher:remove")
    @Log(title = "老师管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(teacherService.deleteTeacherByUserIds(userIds));
    }

    /**
     * 根据登录id活动教师详细信息
     */
     @RequiresPermissions("system:teacher:query")
    @GetMapping(value = "/detail/{loginId}")
    public AjaxResult getDetail(@PathVariable("loginId") int loginId)
    {
        return success(teacherService.selectTeacherByLoginId(loginId));
    }

}
